package com.hxy.quartz.service.impl;

import com.hxy.quartz.dto.QuartzJobInfo;
import com.hxy.quartz.job.MainJob;
import com.hxy.quartz.service.IQuartzService;
import com.hxy.quartz.util.QuartzUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;
import org.springframework.stereotype.Service;

/***
 * QuartzService实现类
 */
@Service
public class QuartzServiceImpl implements IQuartzService {
    // springboot做了配置  直接注入即可
    @Autowired
    private SchedulerFactoryBean factoryBean;

    @Override
    public void add(QuartzJobInfo info) {
        QuartzUtils.addJob(factoryBean.getScheduler(),
                info.getJobName(), MainJob.class,info,info.getCronj());
    }

    @Override
    public void del(String jobName) {
        QuartzUtils.removeJob(factoryBean.getScheduler(),jobName);
    }
}


















